//
// Description: 11. 盛最多水的容器
// Created by Loading on 2021/8/13.
//

#include <bits/stdc++.h>

using namespace std;

int maxArea(vector<int> &height) {
    int res = 0;
    // 双指针
    for (int i = 0, j = (int) height.size() - 1; i < j;) {
        int max_area = min(height[i], height[j]) * (j - i);
        res = max(res, max_area);
        // 选择较短的长度，移动指针
        if (height[i] <= height[j]) {
            ++i;
        } else {
            --j;
        }
    }

    return res;
}

int main() {
    vector<int> height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
    int max_area = maxArea(height);
    cout << max_area << endl;
}